package com.atguigu.day20.exer;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/25 16:11
 * @注释
 */

public class PrintTest {
    int index = 1;

    public synchronized void number(int number) {
            while (index % 3 == 0) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print(number + " ");

            index++;

            this.notifyAll();
    }

    public synchronized void letter(char letter) {
        while (index % 3 != 0) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.print(letter + " ");

        index++;

        this.notifyAll();
    }
}
